package com.solomon.travel.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.solomon.travel.common.custom.mapper.HotelCustomMapper;
import com.solomon.travel.common.custom.po.DiningRoomCustom;
import com.solomon.travel.common.custom.po.HotelCustom;
import com.solomon.travel.common.custom.po.MettingRoomCustom;
import com.solomon.travel.common.mapper.DiningRoomMapper;
import com.solomon.travel.common.mapper.HotelMapper;
import com.solomon.travel.common.mapper.MettingRoomMapper;
import com.solomon.travel.common.mapper.ProtocalMapper;
import com.solomon.travel.common.mapper.RoomPriceMapper;
import com.solomon.travel.common.model.Page;
import com.solomon.travel.common.po.DiningRoom;
import com.solomon.travel.common.po.Hotel;
import com.solomon.travel.common.po.MettingRoom;
import com.solomon.travel.common.po.Protocal;
import com.solomon.travel.common.po.ProtocalExample;
import com.solomon.travel.common.po.RoomPrice;
import com.solomon.travel.common.po.RoomPriceExample;
import com.solomon.travel.common.service.HotelService;

@Service
public class HotelServiceImpl implements HotelService {
	
	@Resource
	private HotelMapper hotelMapper;
	
	@Resource
	private HotelCustomMapper hotelCustomMapper;

	@Override
	public int add(Hotel hotel) {
		return hotelMapper.insertSelective(hotel);
	}

	@Override
	public int update(Hotel hotel) {
		return hotelMapper.updateByPrimaryKeySelective(hotel);
	}

	@Override
	public int add(DiningRoom diningRoom) {
		return diningRoomMapper.insertSelective(diningRoom);
	}

	@Override
	public int add(MettingRoom mettingRoom) {
		return mettingRoomMapper.insertSelective(mettingRoom);
	}

	@Override
	public HotelCustom getHotelByUser(String userId) {
		return hotelCustomMapper.getHotelByUser(userId);
	}

	@Override
	public DiningRoomCustom getDiningRoomByHotel(String hotelId) {
		return hotelCustomMapper.getDiningRoomByHotel(hotelId);
	}

	@Override
	public MettingRoomCustom getMettingRoomByHotel(String hotelId) {
		return hotelCustomMapper.getMettingRoomByHotel(hotelId);
	}
	
	@Resource
	private DiningRoomMapper diningRoomMapper;
	
	@Resource
	private MettingRoomMapper mettingRoomMapper;

	@Override
	public int update(DiningRoom diningRoom) {
		return diningRoomMapper.updateByPrimaryKeySelective(diningRoom);
	}

	@Override
	public int update(MettingRoom mettingRoom) {
		return mettingRoomMapper.updateByPrimaryKeySelective(mettingRoom);
	}

	@Override
	public int add(Protocal protocal) {
		return protocalMapper.insertSelective(protocal);
	}

	@Override
	public int add(RoomPrice roomPrice) {
		return roomPriceMapper.insertSelective(roomPrice);
	}

	@Resource
	private RoomPriceMapper roomPriceMapper;
	
	@Resource
	private ProtocalMapper protocalMapper;

	@Override
	public int update(Protocal protocal) {
		return protocalMapper.updateByPrimaryKeySelective(protocal);
	}

	@Override
	public int update(RoomPrice roomPrice) {
		return roomPriceMapper.updateByPrimaryKeySelective(roomPrice);
	}

	@Override
	public List<RoomPrice> listHotelRoomPrice(String hotelId) {
		RoomPriceExample example = new RoomPriceExample();
		example.createCriteria().andHotelIdEqualTo(hotelId);
		example.setOrderByClause("type");
		return roomPriceMapper.selectByExample(example);
	}

	@Override
	public Protocal getHotelProtocal(String hotelId) {
		ProtocalExample example = new ProtocalExample();
		example.createCriteria().andOrganizationIdEqualTo(hotelId);
		List<Protocal> protocals = protocalMapper.selectByExample(example);
		if (!protocals.isEmpty()) {
			return protocals.get(0);
		}
		return null;
	}

	@Override
	public int count() {
		return hotelMapper.countByExample(null);
	}

	@Override
	public List<Hotel> listHotel(Page page) {
		return hotelCustomMapper.listByPage(page);
	}

	@Override
	public DiningRoom getDiningRoomById(String id) {
		return diningRoomMapper.selectByPrimaryKey(id);
	}

	@Override
	public MettingRoom getMettingRoomById(String id) {
		return mettingRoomMapper.selectByPrimaryKey(id);
	}
	public Integer countBySerch(Hotel hotel, Integer minRoomNum, Integer maxRoomNum) {
		return hotelCustomMapper.countBySerch(hotel, minRoomNum, maxRoomNum);
	}

	@Override
	public List<Hotel> listBySerch(Hotel hotel, Integer minRoomNum, Integer maxRoomNum, Page page) {
		return hotelCustomMapper.listBySerch(hotel, minRoomNum, maxRoomNum, page);
	}
}
